
/**
 * 介绍了访问子类与父类成员的办法，super关键字的介绍
 */

class Base {
    public int a = 11;
    public int b = 22;

    public void test() {
        System.out.println("Base>>");
    }
}
class  Derived extends Base {
    public int c = 33;
    public int a = 1111;//当子类与父类有相同的成员变量


    public void test() {
        System.out.println("Derived>>");
    }
    public void method() {
        System.out.println("a= "+a);//优先访问子类中有的
        System.out.println("a= "+this.a);//可以访问子类/父类
        System.out.println("a= "+super.a);//访问父类的
        System.out.println("b= "+this.b);
        System.out.println("c= "+this.c);
        this.test();
        super.test();
    }
}

public class Test2 {
    public static void main(String[] args) {
        Derived  derived = new  Derived();
        derived.method();
    }


}



/*class Base {
    public int a = 11;
    public int b = 22;
}

class  Derived extends Base {
    public int c = 33;
    public int a = 1111;//当子类与父类有相同的成员变量

    public void method() {
        System.out.println(a);//输出什么结果？
        System.out.println(b);//只有父类中有
        System.out.println(c);//只有子类中有
    }
}

public class Test2 {
    public static void main(String[] args) {
        Derived  derived = new  Derived();
        derived.method();
    }
}*/


/*
class Base {
    public int a = 11;
    public int b = 22;

    public void test() {
        System.out.println("Base>>");
    }
}

class  Derived extends Base {
    public int c = 33;
    public int a = 1111;//当子类与父类有相同的成员变量

    public void test() {
        System.out.println("Derived>>");
    }
    public void method() {

        this.test();
        super.test();

    }
}

public class Test2 {
    public static void main(String[] args) {
        Derived  derived = new  Derived();
        derived.method();
    }
}*/
